package everyday.leetcode.editor.cn;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Stack;

/**
 * @Author: Dang Qi
 * @Date: 2021/3/6  11:42
 * @Description: 503. 下一个更大元素 II
 */
public class NextGreaterElement2 {
    public static void main(String[] args) {
//        Solution solution = new NextGreaterElement2().new Solution();
//        int[] nums = {1,2,1};
//        int[] res = solution.nextGreaterElements(nums);
//        System.out.println(Arrays.toString(res));
        String s = "a";
        System.out.println(s.substring(1,1).length());

    }
    class Solution {
        public int[] nextGreaterElements(int[] nums) {
            int[] ans = new int[nums.length];
            for (int i = 0; i < nums.length; i++) ans[i] = -1;
            Stack<Integer> s = new Stack<>();
            int i = 0;

            while (true) {
                while (!s.isEmpty() && nums[s.peek()] < nums[i])
                    ans[s.pop()] = nums[i];
                if(!s.isEmpty()&&s.peek()==i) break;
                s.push(i);
                i = (i+1) % nums.length;

            }
            return ans;
        }
    }
    public void test(){
        StringBuilder s = new StringBuilder();
        List l = new ArrayList();

    }
}
